#!/usr/bin/env bash


if [ `whoami` != "root" ];then
  echo "must be root"
  exit 1
fi

which "docker" > /dev/null
if [ $? -eq 0 ]
then
    echo "docker已安装"
    exit 1
fi

# sudo apt-get remove docker docker-engine docker.io containerd runc

echo "安装docker..."
mkdir -p /etc/docker

cat <<EOF > /etc/docker/daemon.json
{
"registry-mirrors":[
    "https://hub-mirror.c.163.com",
    "https://registry.aliyuncs.com"
],
"graph":"/var/lib/docker",
"graph":"/var/lib/docker",
"insecure-registries":["localhost:8000"],
"features": { "buildkit": true }
}
EOF



# https://docs.docker.com/engine/install/binaries/
mkdir -p /opt/docker/ && cd /opt/docker

wget https://download.docker.com/linux/static/stable/x86_64/docker-23.0.5.tgz -P /opt/docker/
tar xzvf docker-*.tgz
sudo cp docker/* /usr/bin/

systemctl start docker

echo "开机启动docker..."
systemctl enable docker


# 设置存储位置，需要提前执行以下命令
# mkdir -p /data/docker
# ln -s /data/docker /var/lib/docker
